package LCP;

public class LCP3 {
    public static void main(String[] args) {

    }
    public boolean robot(String command, int[][] obstacles, int x, int y) {
        int a = 0 , b = 0;
        //计算出一次路径x轴和y轴步数
        for(int i = 0 ; i < command.length() ; i++){
            if(command.charAt(i) == 'U') b++;
            else a++;
        }
        //判断能否到达终点
        boolean bl = Helper(command , x , y , a , b);
        if(!bl) return false;
        for (int[] obstacle : obstacles) {
            int p = obstacle[0], q = obstacle[1];
            //障碍物在终点后，跳过
            if (p > x || q > y) continue;
            //判断障碍物是否在路劲上
            if (Helper(command, p, q, a, b)) return false;
        }
        return true;
    }

    public boolean Helper(String command , int x, int y , int a , int b){
        //取离目标点最近的一次路径起点，取最小值
        int num = Math.min(x/a , y/b);
        //得出起点位置
        int a1 = a*num;
        int b1 = b*num;
        //若起点就在目标点上，直接返回true
        boolean bl = a1 == x && b1 == y;
        if(bl) return true;
        //按路径遍历，寻找目标点
        for(int i = 0 ; i < command.length() ; i++){
            if(command.charAt(i) == 'U') b1++;
            else a1++;
            if(a1 > x || b1 > y) return false;
            if(a1 == x && b1 == y){
                bl = true;
                break;
            }
        }
        return true;
    }

}
